﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Admin.Presentation.Controllers
{
    [Authorize]
    [EnsureSsl]
    public class JummahPrayersController : Controller
    {
        [AppendLayoutViewModel]
        public ActionResult Index()
        {
            
            var model = Business.JummahPrayers.Index.PageLoad();
            ViewBag.Message = Request["msg"];
            return View(model);
        }

        [AppendLayoutViewModel]
        public ActionResult CreateLocation(int id)
        {
            
            var model = Business.JummahPrayers.CreateLocation.PageLoad(id);
            return View(model);
        }

        public JsonResult SaveLocation(Adams.Admin.DataTransfer.JummahPrayers.CreateLocation.FormInput input)
        {
            var model = Business.JummahPrayers.CreateLocation.SaveLocation(input);
            return Json(model);
        }

        public RedirectResult DeleteLocation(int id)
        {
            Business.JummahPrayers.Index.DeleteLocation(id);
            var model = new { Deleted = true };
            return Redirect("/JummahPrayers?msg=2");
        }

        [AppendLayoutViewModel]
        public ActionResult CreatePrayer(int id)
        {
            
            var model = Business.JummahPrayers.CreatePrayer.PageLoad(id);
            ViewBag.LocationID = Request["LocationID"].ToInt();
            return View(model);
        }

        public JsonResult SavePrayer(Adams.Admin.DataTransfer.JummahPrayers.CreatePrayer.FormInput input)
        {
            var model = Business.JummahPrayers.CreatePrayer.SavePrayer(input);
            return Json(model);
        }

        public RedirectResult DeletePrayer(int id)
        {
            Business.JummahPrayers.Index.DeletePrayer(id);
            var model = new { Deleted = true };
            return Redirect("/JummahPrayers?msg=4");
        }
    }
}
